{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">

                        <div class="layui-col-md6 layui-input-inline" style="margin-top: 5px">
                            <input type="text" id="user_name" class="layui-input search" name="user_name" value="" placeholder="公司名字|产品名字|资料名称"/>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px">
                            <select name="cpd_type" class="layui-input">
                                <option value="">不限类型</option>
                                <option value="1">图片</option>
                                <option value="2">文档</option>
                                <option value="3">视频</option>
                            </select>
                        </div>
                        <div class="layui-input-inline" style="margin-top: 5px;">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>

                <div class="col-sm-12">
                    <div class="input-group" >
                        <button class="btn btn-primary" type="button" onclick="wk.layer_show('添加资料', '{:url('addData')}')">
                        <i class="fa fa-plus"></i> 添加资料
                        </button>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <!--<div class="col-sm-12">-->
                    <!--<div class="input-group" >-->
                        <!--<button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">-->
                            <!--<i class="fa fa-wrench"></i> 批量操作 <span class="caret"></span>-->
                        <!--</button>-->
                        <!--<ul class="dropdown-menu layui-anim layui-anim-upbit" role="menu">-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="excelAll"><i class="fa fa-external-link"></i> 批量导出</a></li>-->
                            <!--<li><a  href="javascript:;" class="layuiBtn" data-type="excelAllNoSelect"><i class="fa fa-external-link"></i> 全部导出</a></li>-->
                        <!--</ul>-->
                    <!--</div>-->
                <!--</div>-->
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                    <!--修改状态模板-->
                    <script type="text/html" id="cpd_top">
                    <input type="checkbox" value="{{d.cpd_id}}"  lay-skin="switch"  lay-text="置顶|未置顶" lay-filter="OnOff" {{ d.cpd_top == 2 ? 'checked' : '' }} >
                    </script>

                    <!--状态显示模板-->
                    <!--<script type="text/html" id="imgTpl">-->
                    <!--<img src="{{d.rb_image}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />-->
                    <!--</script>-->
                    <!--操作模板-->
                    <script type="text/html" id="cpd_type">
                    {{# if(d.cpd_type == 1){ }}
                    图片
                    {{# } }}
                    {{# if(d.cpd_type == 2){ }}
                    文档
                    {{# } }}
                    {{# if(d.cpd_type == 3){ }}
                    视频
                    {{# } }}
                    </script>
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('查看详情', '{:url('dataInfo')}?cpd_id={{d.cpd_id}}')" class="btn btn-primary btn-xs m-r-xs" title="查看详情">查看详情</a>
                        <a href="javascript:;" onclick="wk.layer_show('编辑', '{:url('editData')}?cpd_id={{d.cpd_id}}')" class="btn btn-primary btn-xs m-r-xs" title="编辑">编辑</a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.cpd_id}}','{:url('dataDel')}','确定删除吗?')" class="btn btn-danger btn-xs m-r-xs" title="删除">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("datas/index")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 300]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
//                {type: 'checkbox', fixed: 'left'},
                  {type:'numbers', width: 70, title: '序号'}
                , {field: 'cpd_id', width: 70, title: '资料id', align: 'center'}
                , {field: 'cpd_name', width: '', title: '资料名称', align: 'center'}
                , {field: 'cpd_type', width: 90, title: '资料类型', align: 'center',templet: '#cpd_type'}
                , {field: 'cp_name', width: 90, title: '所属产品', align: 'center'}
                , {field: 'c_name', width: 90, title: '所属公司', align: 'center'}
                , {field: 'cpd_sort', width: 130, title: '排序值(可编辑)', align: 'center', edit: 'test'}
                , {field: 'cpd_top', width: 90, title: '是否置顶', align: 'center',templet: '#cpd_top'}
                , {field: 'cpd_browse', width: 80, title: '浏览量', align: 'center'}
                , {field: 'cpd_update', width: '', title: '更新时间', align: 'center'}
                , {fixed: 'right', width:240, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //批量操作
        var $ = layui.$, active = {
            //批量导出订单
            excelAllT:function () {
                wk.excelAll(getIds(),$('.layui-input').serialize(),"{:url('outExcelTeam')}");
            },
            //全部导出
            excelAllNoSelectT:function () {
                wk.excelAll('all',$('.layui-input').serialize(),"{:url('outExcelTeam')}");
            }
        };
        //监听单元格编辑---排序
        table.on('edit(testReload)', function(obj){
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            wk.change(data.cpd_id,"{:url('updateSort')}",field,value);
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true ? num = 2: num = 1;
            //用户状态
            wk.status(this.value,num, '{:url("changeTop")}',obj);
        });
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['ct_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>